package Solution.problem073;

import java.util.HashSet;
import java.util.Set;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/06/11 09:55
 */
public class BetterSolution {
    public static void setZeroes(int[][] matrix) {
        if (matrix.length == 0 || matrix[0].length == 0) {
            return;
        }
        int row = matrix.length;
        int col = matrix[0].length;
        int[] rows = new int[row];
        int[] cols = new int[col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if (matrix[i][j] == 0) {
                    rows[i] = -1;
                    cols[j] = -1;
                }
            }
        }
        for (int j = 0; j < col; j++) {
            if (cols[j] == -1) {
                for (int i = 0; i < row; i++) {
                    matrix[i][j] = 0;
                }
            }

        }

        for (int i = 0; i < row; i++) {
            if (rows[i] == -1) {
                for (int j = 0; j < col; j++) {
                    matrix[i][j] = 0;
                }
            }
        }

    }

    public static void main(String[] args) {

        //[[0,1,2,0],[3,4,5,2],[1,3,1,5]]
        int[][] array = new int[][]{{0, 1, 2, 0}, {3, 4, 5, 2}, {1, 3, 1, 5}};
        setZeroes(array);
        System.out.println(array);
    }
}
